.TH std::literals::string_literals::operator""s 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::literals::string_literals::operator""s \- std::literals::string_literals::operator""s

.SH Synopsis
   Defined in header <string>
   std::string operator""s( const char* str, std::size_t    \fB(1)\fP \fI(since C++14)\fP
   len );                                                       (constexpr since C++20)
   constexpr std::u8string operator""s( const char8_t* str, \fB(2)\fP \fI(since C++20)\fP
   std::size_t len );
   std::u16string operator""s( const char16_t* str,         \fB(3)\fP \fI(since C++14)\fP
   std::size_t len );                                           (constexpr since C++20)
   std::u32string operator""s( const char32_t* str,         \fB(4)\fP \fI(since C++14)\fP
   std::size_t len );                                           (constexpr since C++20)
   std::wstring operator""s( const wchar_t* str,            \fB(5)\fP \fI(since C++14)\fP
   std::size_t len );                                           (constexpr since C++20)

   Forms a string literal of the desired type.

   1) Returns std::string{str, len}.
   2) Returns std::u8string{str, len}.
   3) Returns std::u16string{str, len}.
   4) Returns std::u32string{str, len}.
   5) Returns std::wstring{str, len}.

.SH Parameters

   str - pointer to the beginning of the raw character array literal
   len - length of the raw character array literal

.SH Return value

   The string literal.

.SH Notes

   These operators are declared in the namespace std::literals::string_literals, where
   both literals and string_literals are inline namespaces. Access to these operators
   can be gained with either

     * using namespace std::literals, or
     * using namespace std::string_literals, or
     * using namespace std::literals::string_literals.

   std::chrono::duration also defines operator""s, to represent literal seconds, but it
   is an arithmetic literal: 10.0s and 10s are ten seconds, but "10"s is a string.

    Feature-test macro    Value    Std                  Feature
   __cpp_lib_string_udls 201304L \fI(C++14)\fP User-defined literals for string types

.SH Example

   
// Run this code

 #include <iostream>
 #include <string>
  
 void print_with_zeros(auto const note, std::string const& s)
 {
     std::cout << note;
     for (const char c : s)
         c ? std::cout << c : std::cout << "₀";
     std::cout << " (size = " << s.size() << ")\\n";
 }
  
 int main()
 {
     using namespace std::string_literals;
  
     std::string s1 = "abc\\0\\0def";
     std::string s2 = "abc\\0\\0def"s;
     print_with_zeros("s1: ", s1);
     print_with_zeros("s2: ", s2);
  
     std::cout << "abcdef"s.substr(1,4) << '\\n';
 }

.SH Output:

 s1: abc (size = 3)
 s2: abc₀₀def (size = 8)
 bcde

.SH See also

   constructor   constructs a basic_string
                 \fI(public member function)\fP 
   operator""sv  creates a string view of a character array literal
   \fI(C++17)\fP       \fI(function)\fP 
